#ifndef __UI_Gauge_SPI_H
#define __UI_Gauge_SPI_H

#ifdef APM32E10X_HD
	#include "apm32e10x_gpio.h"      
	#include "apm32e10x_rcm.h"    
	#include "apm32e10x_spi.h"

#elif defined AT32F403AVGT7
	#include "at32f403a_407_gpio.h"
	#include "at32f403a_407_spi.h"
	#include "at32f403a_407_crm.h"

#else
	#include "apm32f10x_gpio.h"     
	#include "apm32f10x_rcm.h" 
	#include "apm32f10x_spi.h"
	
#endif
#include "BoardData.h"

//////////////////////// SPI 引脚上拉控制 /////////////////////////
#define  UIGauge_spi_pullup       1       // >0 使能上拉


// 计量芯片 //
//引脚块1 = 过0引脚 = 过0点有高电平输入 
#define Gauge_RCM               RCM_APB2_PERIPH_GPIOA                         
#define Gauge_PinPort           GPIOA    

#ifdef SQDri_EVSEB_11KW
	// 过零检测引脚 = PA13
	#define Zero_PinId              GPIO_PIN_13
#else
	// 过零检测引脚 = PC5
	#define Zero_RCM                RCM_APB2_PERIPH_GPIOC                         
	#define Zero_PinPort            GPIOC    
	#define Zero_PinId              GPIO_PIN_5
#endif

// SPI通讯
#define SPI_CS_PinId            GPIO_PIN_4 
#define SPI_SCLK_PinId          GPIO_PIN_5  
#define SPI_MOSI_PinId          GPIO_PIN_7  
#define SPI_MISO_PinId          GPIO_PIN_6  

// SPI功能
#define Gauge_SPI_RCM           RCM_APB2_PERIPH_SPI1
#define Gauge_SPI_id            SPI1


// 定义函数
#define SPI_bit_set(x)          Gauge_PinPort -> BSC = x
#define SPI_bit_reset(x)        Gauge_PinPort -> BC  = x

#ifdef Zero_PinPort
#define SPI_Zero_set(x)          Zero_PinPort -> BSC = x
#define SPI_Zero_reset(x)        Zero_PinPort -> BC  = x    
#endif


///// 函数声明 //////
void SPI_Gauge_init(void);
void rn_zero_init(void); 
uint8_t SPI_SendRead_Byte(uint8_t data);

#endif


